package com.swt.gap.controller;


import com.swt.gap.common.constant.CommonConstant;
import com.swt.gap.model.entity.SysIcon;
import com.swt.gap.model.vo.IconVO;
import com.swt.gap.model.vo.SysIconListVO;
import com.swt.gap.model.vo.SysIconVO;
import com.swt.gap.service.SysIconService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "图标")
@RestController
@RequestMapping("/icon")
@Slf4j
public class SysIconController {

    private final SysIconService sysIconService;

    public SysIconController(SysIconService sysIconService) {
        this.sysIconService = sysIconService;
    }

    @PostMapping("/icons")
    @ApiOperation(value = "上传并保存icon", notes = "上传并保存icon")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SysIcon.class, responseContainer = "List")})
    public ResponseEntity uploadEntityIcon(@RequestParam("files") MultipartFile[] files) {
        return ResponseEntity.ok(sysIconService.addIcon(files, CommonConstant.ICON_PATH));
    }


    @GetMapping("/icons")
    @ApiOperation(value = "获取图标列表", notes = "获取图标列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SysIconListVO.class, responseContainer = "List")})
    public ResponseEntity listEntityIcons() {
        return ResponseEntity.ok(sysIconService.getAllIcons());
    }


    @DeleteMapping("/{iconId}")
    @ApiOperation(value = "删除未使用的图标", notes = "删除未使用的图标")
    @ApiImplicitParam(name = "iconId", dataType = "int",paramType = "path", value = "图标Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    public ResponseEntity deleteIcon(@PathVariable Integer iconId){
        return ResponseEntity.ok(sysIconService.deleteIcon(iconId));
    }


    @PostMapping("/icons/draw")
    @ApiOperation(value = "画图上传", notes = "画图上传")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = IconVO.class, responseContainer = "List")})
    public ResponseEntity uploadPaintIcon(@RequestParam("files") MultipartFile[] files) {
        return ResponseEntity.ok(sysIconService.addPaintIcon(files, CommonConstant.ICON_PATH));
    }

    @GetMapping("/icons/draw")
    @ApiOperation(value = "获取画图图标列表", notes = "获取画图图标列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SysIconVO.class, responseContainer = "List")})
    public ResponseEntity listPaintIcons() {
        return ResponseEntity.ok(sysIconService.getPaintIcons());
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取全部图标地址", notes = "获取全部图标地址")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SysIconVO.class, responseContainer = "List")})
    public ResponseEntity<List<SysIconVO>> listAllIcons() {
        return ResponseEntity.ok(sysIconService.listAllIcons());
    }

}
